# RUN: llc %s -o - -experimental-debug-variable-locations=true \
# RUN:   -run-pass=livedebugvalues \
# RUN: | FileCheck %s --implicit-check-not=DBG_VALUE
# RUN: llc %s -o - -experimental-debug-variable-locations=true \
# RUN:   -start-before=livedebugvalues -filetype=obj \
# RUN: | llvm-dwarfdump - | FileCheck %s --check-prefix=DWARF
#
# LLVM can produce DIExpressions that convert from one value of arbitrary size
# to another. This is normally fine, however that means the value for a
# variable tracked in instruction referencing might not be the same size as the
# variable itself.
#
# This becomes a problem when values move onto the stack and we emit
# DW_OP_deref: there is no information about how large a value the consumer
# should load from the stack. The convention today appears to be the size of
# the variable, and as a result if you have a value that's smaller than the
# variable size, extra information is loaded onto the DWARF expression stack.
# This then appears as a false variable value to the consumer.
#
# In this test, there are various scenarios to test where the size of the value
# needs to reach the expression emitter in LiveDebugValues. However, there are
# even more scenarios to consider where the value is in a spill slot, and:
#  * The value is larger than the variable, the same, or smaller,
#  * The variable is a normal scalar, or a fragment,
#  * There is a DW_OP_stack_value in the expression, or not
# That gives us twelve situations to consider, and the easiest way to confirm
# correctness is to write them all out. The final DWARF expressions to
# produce are:
# * No stack value,
#   * Scalar (32 bits),
#     * Larger value (64 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value
#     * Same value (32 bits)
#       DW_OP_breg7 RSP-8
#     * Smaller value (8 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value
#   * Fragment (32 bits)
#     * Larger value (64 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value, DW_OP_piece 0x4
#     * Same value (32 bits)
#       DW_OP_breg7 RSP-8, DW_OP_piece 0x4
#     * Smaller value (8 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value, DW_OP_piece 0x4
# * Stack value (imagine there was some arithmetic on the stack before the
#   DW_OP_stack_value opcode),
#   * Scalar (32 bits),
#     * Larger value (64 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value
#     * Same value (32 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref, DW_OP_stack_value
#     * Smaller value (8 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value
#   * Fragment (32 bits)
#     * Larger value (64 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value, DW_OP_piece 0x4
#     * Same value (32 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x4, DW_OP_stack_value, DW_OP_piece 0x4
#     * Smaller value (8 bits)
#       DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value, DW_OP_piece 0x4
#
# The outlier from the pattern is (Stack value, Fragment, Same value size): we
# put a DW_OP_deref_size in where a DW_OP_deref could have sufficied. However,
# if we used DW_OP_deref, it would force the consumer to derive the deref size
# from the DW_OP_piece, which is un-necessarily hard.

## Capture variable num,
# CHECK-DAG: ![[VARNUM:[0-9]+]] = !DILocalVariable(name: "flannel",
# CHECK-DAG: ![[VARNUM2:[0-9]+]] = !DILocalVariable(name: "shoes",

# DWARF:      DW_TAG_variable
# DWARF-NEXT: DW_AT_location
## Defined in register, spilt to stack.
# DWARF-NEXT: DW_OP_breg0 RAX+0, DW_OP_constu 0xff, DW_OP_and, DW_OP_convert (0x00000026) "DW_ATE_signed_8", DW_OP_convert (0x0000002a) "DW_ATE_signed_32", DW_OP_stack_value
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_convert (0x00000026) "DW_ATE_signed_8", DW_OP_convert (0x0000002a) "DW_ATE_signed_32", DW_OP_stack_value
## Defined on stack.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_convert (0x00000026) "DW_ATE_signed_8", DW_OP_convert (0x0000002a) "DW_ATE_signed_32", DW_OP_stack_value
## DBG_PHI that moves to stack.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value
## DBG_PHI of stack with size.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x2, DW_OP_stack_value
## Followed by scalar / no-stack-value locations with various sizes.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value
# DWARF-NEXT: DW_OP_breg7 RSP-8
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value
## scalar / stack value with various sizes.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value)
# DWARF:      DW_AT_name ("flannel")

# Variable with fragments.
# DWARF:      DW_TAG_variable
# DWARF-NEXT: DW_AT_location
## Scalar / no-stack-value locations with various sizes.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_stack_value, DW_OP_piece 0x4
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_piece 0x4
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_stack_value, DW_OP_piece 0x4
## Scalar / stack value with various sizes.
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x8, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value, DW_OP_piece 0x4
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x4, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value, DW_OP_piece 0x4
# DWARF-NEXT: DW_OP_breg7 RSP-8, DW_OP_deref_size 0x1, DW_OP_lit1, DW_OP_plus, DW_OP_stack_value, DW_OP_piece 0x4)
# DWARF:      DW_AT_name ("shoes")

--- |
  ; ModuleID = 'missingvar.ll'
  source_filename = "a"
  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-unknown-linux-gnu"
  
  define linkonce_odr void @_ZNSt5dequeIPN4llvm4LoopESaIS2_EE13_M_insert_auxESt15_Deque_iteratorIS2_RS2_PS2_EmRKS2_() local_unnamed_addr align 2 !dbg !3 {
  entry:
    call void @llvm.dbg.value(metadata i32 0, metadata !8, metadata !DIExpression()), !dbg !7
    call void @llvm.dbg.value(metadata i32 0, metadata !10, metadata !DIExpression()), !dbg !7
    ret void
  }

  declare void @llvm.dbg.value(metadata, metadata, metadata)
  
  !llvm.module.flags = !{!0, !9}
  !llvm.dbg.cu = !{!1}
  
  !0 = !{i32 2, !"Debug Info Version", i32 3}
  !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
  !2 = !DIFile(filename: "bees.cpp", directory: "")
  !3 = distinct !DISubprogram(name: "nope", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1)
  !4 = !DISubroutineType(types: !5)
  !5 = !{!6}
  !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !7 = !DILocation(line: 1, scope: !3)
  !8 = !DILocalVariable(name: "flannel", scope: !3, type: !6)
  !9 = !{i32 2, !"Dwarf Version", i32 5}
  !10 = !DILocalVariable(name: "shoes", scope: !3, type: !11)
  !11 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)


...
---
name:            _ZNSt5dequeIPN4llvm4LoopESaIS2_EE13_M_insert_auxESt15_Deque_iteratorIS2_RS2_PS2_EmRKS2_
alignment:       16
tracksRegLiveness: true
debugInstrRef: true
liveins:
  - { reg: '$rdi' }
  - { reg: '$rsi' }
  - { reg: '$rdx' }
frameInfo:
  stackSize:       48
  offsetAdjustment: -48
  maxAlignment:    8
  maxCallFrameSize: 0
  cvBytesOfCalleeSavedRegisters: 48
fixedStack:
  - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, callee-saved-register: '$rbx' }
  - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, callee-saved-register: '$r12' }
  - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, callee-saved-register: '$r13' }
  - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, callee-saved-register: '$r14' }
  - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '$r15' }
  - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '$rbp' }
stack:
  - { id: 0, type: spill-slot, offset: -64, size: 8, alignment: 8 }
machineFunctionInfo: {}
body:             |
  bb.0.entry:
    liveins: $rdi, $rdx, $rsi, $rbp, $r15, $r14, $r13, $r12, $rbx
  
    ; CHECK-LABEL: bb.0.entry:

    ;; PART ONE: For this first block of tests, check that information about
    ;; the size of the value on the stack makes it through to the expression.

    $al = MOV8ri 0, debug-instr-number 1, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), dbg-instr-ref(1, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_convert, 8, DW_ATE_signed,
    ; CHECK-SAME     : DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), $al

    MOV8mr $rsp, 1, $noreg, -8, $noreg, renamable $al :: (store 1 into %stack.0)
    ;; Clobber to force variable location onto stack. We should use a
    ;; deref_size 1 because the value is smaller than the variable.
    $al = MOV8ri 0, debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, 
    ; CHECK-SAME:     DW_OP_deref_size, 1, DW_OP_LLVM_convert, 8, DW_ATE_signed,
    ; CHECK-SAME:     DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), $rsp

    ; Terminate the current variable location,
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg, ![[VARNUM]], !DIExpression()

    ;; Try again, but with the value originating on the stack, to ensure that
    ;; we can find its size. It should be deref_size 1 again.
    INC8m $rsp, 1, $noreg, 4, $noreg, implicit-def dead $eflags, debug-instr-number 2, debug-location !7 :: (store (s8) into %stack.0)
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), dbg-instr-ref(2, 1000000), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus,
    ; CHECK-SAME:     DW_OP_deref_size, 1, DW_OP_LLVM_convert, 8, DW_ATE_signed,
    ; CHECK-SAME:     DW_OP_LLVM_convert, 32, DW_ATE_signed, DW_OP_stack_value), $rsp

    $eax = MOV32ri 0, debug-location !7

    ;; How about DBG_PHIs? The size of the value is communicated by the register
    ;; size, or an extra DBG_PHI operand, and that should feed through into the
    ;; decision of whether to deref_size or not.

    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg

    $al = MOV8ri 0, debug-location !7
    DBG_PHI $al, 7

    MOV32mr $rsp, 1, $noreg, -8, $noreg, renamable $eax :: (store 4 into %stack.0)
    $eax = MOV32ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(7, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 1, DW_OP_stack_value), $rsp

    $eax = MOV32ri 0, debug-location !7

    ;; And for when the DBG_PHI specifies a stack size...
    DBG_PHI %stack.0, 8, 16
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(8, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 2, DW_OP_stack_value), $rsp

    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; PART TWO: test the twelve kinds of location expression mentioned in the
    ;; opening comment of this test, in that order. Please update the opening
    ;; comment, these lines and the DWARF check lines at the same time.
    ;; In each test we'll state a location, give it an instruction to cover,
    ;; and then terminate it.

    ;; Scalar (32), Large value (64), no stack value,
    $rax = MOV64ri 0, debug-instr-number 10, debug-location !7
    MOV64mr $rsp, 1, $noreg, -8, $noreg, renamable $rax :: (store 8 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(10, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 8, DW_OP_stack_value), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Scalar (32), Same value size (32), no stack value,
    $eax = MOV32ri 0, debug-instr-number 11, debug-location !7
    MOV32mr $rsp, 1, $noreg, -8, $noreg, renamable $eax :: (store 4 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(11, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Scalar (32), Smaller value (8), no stack value,
    $al = MOV8ri 0, debug-instr-number 12, debug-location !7
    MOV8mr $rsp, 1, $noreg, -8, $noreg, renamable $al :: (store 1 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(12, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 1, DW_OP_stack_value), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Larger value (64), no stack value,
    $rax = MOV64ri 0, debug-instr-number 13, debug-location !7
    MOV64mr $rsp, 1, $noreg, -8, $noreg, renamable $rax :: (store 8 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(13, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 8, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Same value size (32), no stack value,
    $eax = MOV32ri 0, debug-instr-number 14, debug-location !7
    MOV32mr $rsp, 1, $noreg, -8, $noreg, renamable $eax :: (store 4 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(14, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Smaller value (8), no stack value,
    $al = MOV8ri 0, debug-instr-number 15, debug-location !7
    MOV8mr $rsp, 1, $noreg, -8, $noreg, renamable $al :: (store 1 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(15, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 1, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg



    ;; Scalar (32), Large value (64), with stack value,
    $rax = MOV64ri 0, debug-instr-number 16, debug-location !7
    MOV64mr $rsp, 1, $noreg, -8, $noreg, renamable $rax :: (store 8 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), dbg-instr-ref(16, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 8, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Scalar (32), Same value size (32), no stack value,
    $eax = MOV32ri 0, debug-instr-number 17, debug-location !7
    MOV32mr $rsp, 1, $noreg, -8, $noreg, renamable $eax :: (store 4 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), dbg-instr-ref(17, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Scalar (32), Smaller value (8), no stack value,
    $al = MOV8ri 0, debug-instr-number 18, debug-location !7
    MOV8mr $rsp, 1, $noreg, -8, $noreg, renamable $al :: (store 1 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !8, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), dbg-instr-ref(18, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 1, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !8, !DIExpression(), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Larger value (64), no stack value,
    $rax = MOV64ri 0, debug-instr-number 19, debug-location !7
    MOV64mr $rsp, 1, $noreg, -8, $noreg, renamable $rax :: (store 8 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(19, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 8, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Same value size (32), no stack value,
    $eax = MOV32ri 0, debug-instr-number 20, debug-location !7
    MOV32mr $rsp, 1, $noreg, -8, $noreg, renamable $eax :: (store 4 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(20, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 4, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    ;; Fragment (32), Smaller value (8), no stack value,
    $al = MOV8ri 0, debug-instr-number 21, debug-location !7
    MOV8mr $rsp, 1, $noreg, -8, $noreg, renamable $al :: (store 1 into %stack.0)
    $rax = MOV64ri 0, debug-location !7
    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(21, 0), debug-location !7
    ; CHECK:      DBG_VALUE_LIST ![[VARNUM2]],
    ; CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 8, DW_OP_minus, DW_OP_deref_size, 1, DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32), $rsp
    $eax = MOV32ri 0, debug-location !7
    DBG_VALUE $noreg, $noreg, !10, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !7
    ; CHECK: DBG_VALUE $noreg, $noreg

    RET64 0, debug-location !7
...
